// base
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Button } from '@tarojs/components'
// less
import './index.less'
import If from '../../../../components/page-components/if'
import { getGlobalData, getGlobalDeepData } from '../../../../configuration/globaldata'
import { showToast } from '../../../../crossplatform/apiservice/toast'
import { deepCopy } from '../../../../util/lodashmin'
import scaleImageSrc from '../../../../util/pagemethods/scaleImageSrc'

class HeaderDetail extends Component {
  static defaultProps = {
    myMessage: [],
    detail: {}
  }
  componentWillMount () {
    // onLoad
  }

  componentDidMount () {
    // onready
  }

  componentWillUnmount () {
    // onUnload
  }

  componentWillReceiveProps (nextprops) {}

  getEducationMessage = education => {
    // const list = getGlobalDeepData('education', data.value)
    return getGlobalDeepData('education', data.value)
    // list.forEach((data) => {
    // 	if (education == data.value) {
    // 		name = data.name
    // 	}
    // })
    // return name
  }

  dealMessageData = myMessage => {
    for (let i of myMessage) {
      if (i.name === '现居') {
        let val = i.value
        return val.split(' ')[1] || val
      }
    }
  }

  delay (time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }

  insertPost = () => {
    const {
      archiveId,
      detail: { isOld }
    } = this.props
    if (isOld) {
      // 老平台数据 无法收藏
      showToast({
        title: '收藏失败'
      })
    } else {
      this.props.onInsertPost({ archiveId })
    }
  }

  onEscPost = () => {
    this.props.onEscPost()
  }

  dealWorkNature = dataSource => {
    // 去掉 岗位中的  全职
    let dataNew = {
      data: [],
      hasInternship: false
    }
    let data = deepCopy(dataSource)
    if (data && data.length) {
      data.forEach((itemWork, indexWork) => {
        if (itemWork == '实习') {
          dataNew.hasInternship = true
          data.splice(indexWork, indexWork + 1)
        } else {
        }
      })
      dataNew.data = data
      return dataNew
    } else {
      return dataNew
    }
  }

  render () {
    const { detail, role, calyears, collected, myMessage, worknature } = this.props
    const myCity = this.dealMessageData(myMessage)
    // 去掉实习
    const worknatureNew = this.dealWorkNature(worknature)

    const { isOld } = detail
    return (
      <View className="HeaderDetail_id12653">
        <View className="abs-img-wrap">
          <View className="abs-img-text">达人</View>
          <View className="abs-img-white" />
          <Image className="abs-img" src={scaleImageSrc(detail.userAvator, 750)} mode="widthFix" />
        </View>
        <View className="title-people" />
        <View className="wrap-white-box">
          <View className="abs-advater">
            <Image src={scaleImageSrc(detail.userAvator)} className="image-advater" />
          </View>

          <View className="header-wrap">
            <View className="al-top">
              <View className="name">{detail.userName}</View>
              <View className={`sexwrap ${detail.extra == '女' ? 'sexwrap-girl' : ''}`}>
                {detail.extra == '女' ? 'girl' : 'boy'}
              </View>
              <View className="jobtypewrap">
                <View className="jobtype-container">
                  {worknatureNew.data.map((dataWork, indexWork) => {
                    return (
                      <If
                        visible={worknatureNew.data.length > 1}
                        renderElse={
                          <If
                            visible={dataWork == '兼职'}
                            renderElse={<View className="jobtype jobtypequan">{dataWork}</View>}
                          >
                            <View className="jobtype">{dataWork}</View>
                          </If>
                        }
                      >
                        <If
                          visible={dataWork == '兼职'}
                          renderElse={<View className="jobtype jobtypequan">{dataWork[0]}</View>}
                        >
                          <View className="jobtype">{dataWork[0]}</View>
                        </If>
                      </If>
                    )
                  })}
                </View>
                <If visible={role == 'company'}>
                  <View className="wrap-for-collection">
                    <View className="imgwrap-setButton">
                      <Button className="setButton" OpenType="share" />
                      <Image
                        className="imgwrap"
                        src="https://imagesize.hrwork.com/sp/files/260a5ad7-0eab-4707-93cf-f1f940facde1.png"
                      />
                    </View>
                    <If visible={!isOld}>
                      <View className="verticalline" />
                    </If>
                    <If visible={!isOld}>
                      <If
                        visible={collected && !isOld}
                        renderElse={
                          <Image
                            onClick={this.insertPost}
                            className="imgwrap"
                            src="https://imagesize.hrwork.com/sp/files/e5b8d42c-beee-4e5d-bb12-1ae51b028660.png"
                          />
                        }
                      >
                        <Image
                          onClick={this.onEscPost}
                          className="imgwrap"
                          src="https://imagesize.hrwork.com/sp/files/1879b5e3-89c3-45fe-9c74-a6f6329743f4.png"
                        />
                      </If>
                    </If>
                  </View>
                </If>
              </View>
            </View>
          </View>
          <View className="content-wrap">
            <View className="content-wrap-age">{calyears ? calyears + ' ' : ''}</View>
            <View className="content-wrap-line" />
            <View className="content-wrap-city">{myCity}</View>
            <If visible={detail.education}>
              <View className="content-wrap-dot"> · </View>
            </If>
            <If visible={detail.education}>
              <View className="content-wrap-edu">{detail.education ? detail.education : ''}</View>
            </If>
            <If visible={worknatureNew.hasInternship}>
              <View className="content-wrap-dot"> · </View>
            </If>
            <If visible={worknatureNew.hasInternship}>
              <View className="content-wrap-job">{worknatureNew.hasInternship ? '实习' : ''}</View>
            </If>
          </View>
          <Image
            src="https://imagesize.hrwork.com/sp/files/5f97655b-0752-43a3-be51-9e679707a405.png"
            className="img-wrap"
          />
          <View className="desc-wrap">{detail.skillDescription || '这是一个神秘的人物～'}</View>
        </View>
      </View>
    )
  }
}

export default HeaderDetail
